package com.duowei.kitchenshow.service;
import com.duowei.kitchenshow.R;
import com.duowei.kitchenshow.app.MyApp;
import com.duowei.kitchenshow.httputils.Post;
import com.duowei.kitchenshow.utils.SpUtils;

import java.util.TimerTask;

public class MyTimeTask extends TimerTask {
    private String sql;
    private static String callSql="delete from CFPB where  XH in (select XH from CFPB where SL = TDSL)|" +

            "delete from KDSCall where XH in (select top 1 XH from KDSCall where BillNo in (select BillNo from KDSCall group by BillNo having count(*) > 1))|" +

            "insert into KDSCALL (TableNo, XDSJ, BillNo, YHJ) select replace(BY1, ',', ''), getdate(), wmdbh, '0' from CFPB where XDSJ BETWEEN DATEADD(mi,-180,GETDATE())" +
            " AND GETDATE() and XH in (select min(XH) from CFPB group by wmdbh) and wmdbh not in (select BillNo from KDSCALL)|";
    private final String callStyle;

    public MyTimeTask(String sql) {
        this.sql=sql;
        callStyle = (String) SpUtils.get(MyApp.getContext().getString(R.string.callStyle), "padCall");
    }

    public void setSql(String sql) {
        this.sql = sql;
    }

    @Override
    public void run() {
        Post.getInstance().postCfpb(sql);
        if("tvCall".equals(callStyle)){
            Post.getInstance().postCall(callSql,false);
        }
    }
}
